<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../static/css/base.css"/>
    <link rel="stylesheet" href="../static/css/index.css">
</head>
<body>
<%--<div class="head" style="background-image: url(../img/bg_header_index_top.png); height: 50px">--%>
<%--    <div class="container-fluid">--%>
<%--        <!-- Brand and toggle get grouped for better mobile display -->--%>
<%--        <div class="navbar-header">--%>
<%--            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"--%>
<%--                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">--%>
<%--                <span class="sr-only">Toggle navigation</span>--%>
<%--                <span class="icon-bar"></span>--%>
<%--                <span class="icon-bar"></span>--%>
<%--                <span class="icon-bar"></span>--%>
<%--            </button>--%>
<%--            <a class="navbar-brand" href="#">此处是logo</a>--%>
<%--        </div>--%>

<%--        <!-- Collect the nav links, forms, and other content for toggling -->--%>
<%--        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">--%>
<%--            <ul class="nav navbar-nav" style="margin-right: 2px">--%>
<%--                <li><a href="#">首页</a></li>--%>
<%--                <li><a href="http://localhost:8888/html/allhotel.html">国内酒店</a></li>--%>
<%--                <li><a href="#">国外酒店</a></li>--%>
<%--                <li><a href="#">特卖专区</a></li>--%>
<%--                <li class="active"><a href="http://localhost:8888/html/index.html">旗下品牌</a></li>--%>
<%--                <li><a href="#">华住会</a></li>--%>
<%--                <li><a href="#">华住商旅</a></li>--%>
<%--            </ul>--%>

<%--            <ul class="nav navbar-nav navbar-right">--%>
<%--                <li style="margin-right: 30px;margin-top: 10px">--%>
<%--                    <button type="button" class="btn btn-primary small " style=";height: 30px;width:70px">登录</button>--%>
<%--                </li>--%>
<%--                <li style="margin-right: 30px;margin-top: 10px">--%>
<%--                    <button type="button" class="btn btn-default small active" style=";height: 30px;width:70px">注册--%>
<%--                    </button>--%>
<%--                </li>--%>
<%--            </ul>--%>
<%--        </div>--%>
<%--    </div>--%>
<%--</div>--%>
<div class="container-fluid">
    <div class="row" style="margin-top: 50px;">
        <p class="col-md-offset-1 title1" style="color: indianred">密  码  变  更</p>
        <hr>
        <div class="col-md-6 col-md-offset-1">
            <form id="form1" class="form-horizontal" action="" method="post">
                <div class="form-group inputpadding">
                    <label for="input1" class="col-sm-2 control-label">原密码</label>
                    <div class="col-sm-8">
                        <input type="password" class="form-control" name="originpassword" id="input1" placeholder="输入原密码">
                    </div>
                </div>
                <div class="form-group inputpadding">
                    <label for="input2" class="col-sm-2 control-label">新密码</label>
                    <div class="col-sm-8">
                        <input type="password" class="form-control" name="newpassword" id="input2" placeholder="输入新密码">
                    </div>
                </div>
                <div class="form-group inputpadding">
                    <label for="input3" class="col-sm-2 control-label">重复新密码</label>
                    <div class="col-sm-8">
                        <input type="password" class="form-control" name="repeatpassword" id="input3" placeholder="重复新密码">
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-8">
                        <button type="button" class="btn btn-danger col-md-12" onclick="save()" id="button1">修改</button>
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-offset-2 col-sm-8">
                        <p id="warningtip" class="col-md-12" style="text-align: center;color: red" ></p>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<div class="container-fluid">
    <div class="row" style="margin-top: 30px; background-color: #f5f5f5;height: 150px;" >
        <div class="col-md-6 col-md-offset-3" >
            <div class="col-md-2" style="text-align: center;margin-top: 30px;">
                <a href="#">网站介绍</a>
            </div>
            <div class="col-md-2" style="text-align: center;margin-top: 30px;">
                <a href="#">酒店加盟</a>
            </div>
            <div class="col-md-2" style="text-align: center;margin-top: 30px;">
                <a href="#">职位招聘</a>
            </div>
            <div class="col-md-2" style="text-align: center;margin-top: 30px;">
                <a href="#">意见反馈</a>
            </div>
            <div class="col-md-2" style="text-align: center;margin-top: 30px;">
                <a href="#">联系我们</a>
            </div>
        </div>

    </div>

</div>

<script src="../static/bootstrap/js/jquery-3.3.1.js"></script>
<script>
    var flag = true;

    function save() {

        if (!flag){
            return;
        }

        $('#warningtip').text("")
        var originpassword = $('#input1').val()
        var newpassword = $('#input2').val()
        var repeatpassword = $('#input3').val()

        if (originpassword == "undefined"||originpassword==null||originpassword==""){
            $('#warningtip').text("原密码不能为空")
            return
        }
        if (newpassword == "undefined"||newpassword==null||newpassword==""){
            $('#warningtip').text("新密码不能为空")
            return;
        }
        if (repeatpassword!=newpassword){
            $('#warningtip').text("两次密码输入不一致")
            return;
        }


        var formData = new FormData();
        formData.append("originPassword",originpassword)
        formData.append("newPassword",newpassword)

        $.ajax({
            url:"/user/changepassword",
            type:"post",
            processData: false, //jquery 是否对数据进行 预处理
            contentType: false, // 不要自己修改请求内容类型,
            data:formData,
            dataType:"text",
            success:function (data) {
                console.log(data)

                if(data=="success"){

                    flag = false

                    $('#warningtip').text("修改成功")
                    alert("需要重新登录")
                    setTimeout(function () {
                        window.top.location.href = "/login"
                    },1000)

                } else if (data=="loginfail") {
                    alert("登录已失效，请重新登录")
                    setTimeout(function () {
                        window.top.location.href = "/login"
                    },1000)
                }else if (data=="orifail"){
                    $('#warningtip').text("原密码错误")
                    $('#input1').val("")
                    $('#input2').val("")
                    $('#input3').val("")
                }else{
                    $('#warningtip').text("修改失败")
                }
            }
        })






    }


</script>
</body>
</html>